package com.fhz.day006.sp

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

/**
 * 时间:2021/10/20
 * @author msfeng
 * 简述: TODO
 */
class Main4ViewModel(n:Int): ViewModel(){

    //固定,没有办法直接通知页面
//    var num = n
    //因为需要让数据源变化的时候,去自动的通知页面
    val count = MutableLiveData<Int>()

    val s = MutableLiveData<String>()

    init {
        count.value = n
    }

    fun add(){
        var c = count.value ?: 0
        count.value = c + 1
    }

    fun mins(){
        count.value = count.value?.plus(1)
    }

}